n = input()
mi = 30000000
ma = -30000000
if 999 < int(n) < 10000:
    
    for left in range(4):
        for right in range(left, 4):
            num = int(n[left:right+1])
            k = 0  
            for i in range(2, num // 2 +1):         
                if num % i == 0:
                    k = k + 1
            if k == 0 and num != 0 and num != 1:
                if num > ma:
                    ma = num
    if ma == -30000000:
        print("0")
    else:
        print(ma)
else:
    print("0")
